package com.example.documentsearchengine.api;

import com.example.documentsearchengine.dao.Result;
import com.example.documentsearchengine.searcher.DocSearcher;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
public class DocSearcherController {
    //给static修饰 使searcher.DocSearcher成全局唯一
    private static DocSearcher docSearcher=new DocSearcher();
    private ObjectMapper objectMapper;
    @RequestMapping("/searcher")
    public List<Result> searcher(String query){
        if(!StringUtils.hasLength(query)){
            log.info("输入的参数有误");
            return null;
        }
       return docSearcher.search(query);
    }
}
